import request from '@/utils/request'

export default {
  userList(page, limit, searchObj) {
    return request({
      url: `/system/user/list/${page}/${limit}`,
      method: 'post',
      data: searchObj
    });
  },
  getById(id) {
    return request({
      url: `/system/user/get/${id}`,
      method: 'get'
    })
  },
  addUser(user) {
    return request({
      url: '/system/user/add',
      method: 'post',
      data: user
    })
  },
  updateUser(user) {
    return request({
      url: '/system/user/update',
      method: 'put',
      data: user
    })
  },
  changeUserState(id, state) {
    const data = {
      id,
      state
    }
    return request({
      url: '/system/user/changeUserState',
      method: 'put',
      data: data
    });
  },
  removeById(id) {
    return request({
      url: `/system/user/remove/${id}`,
      method: 'delete'
    })
  },
  removeBatchs(idList) {
    return request({
      url: '/system/user/removeBatchs',
      method: 'delete',
      data: idList
    });
  },
}

// 查询用户个人信息
export function getUserProfile() {
  return request({
    url: '/system/user/profile',
    method: 'get'
  })
}

// 修改用户个人信息
export function updateUserProfile(data) {
  return request({
    url: '/system/user/profile',
    method: 'put',
    data: data
  })
}

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    newPassword
  }
  return request({
    url: '/system/user/profile/updatePwd',
    method: 'put',
    params: data
  })
}

// 用户头像上传
export function uploadAvatar(data) {
  return request({
    url: '/system/user/profile/avatar',
    method: 'post',
    data: data
  })
}